package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {
    /**
     * 按名称和类型选择类别
     *
     * @param name 姓名
     * @param type 类型
     * @return {@link List}<{@link Category}>
     */
    List<Category> selectCategoryByNameAndType(String name, Integer type);

    /**
     * 添加类别
     *
     * @param category 类别
     */
    void addCategory(Category category);

    /**
     * 按id选择类别
     *
     * @param id id
     * @return {@link Category}
     */
    @Select("select id, type, name, sort, status, create_time, update_time, create_user, update_user from category where id=#{id}")
    Category selectCategoryById(Long id);

    /**
     * 按id删除类别
     *
     * @param category 类别
     */
    @Delete("delete from category where id=#{id}")
    void deleteCategoryById(Category category);

    /**
     * 修改分类
     *
     * @param category 类别
     */
    @AutoFill(OperationType.UPDATE)
    void modifyClassification(Category category);

    /**
     * 按id获取类别
     *
     * @param id id
     * @return {@link Category}
     */
    @Select("select id, type, name, sort, status, create_time, update_time, create_user, update_user from category where id=#{id}")
    Category getCategoryById(Long id);

    /**
     * 按类型查询
     *
     * @param type 类型
     * @return {@link List}<{@link Category}>
     */
    @Select("select id, type, name, sort, status, create_time, update_time, create_user, update_user from category where type=#{type}")
    List<Category> queryByType(Integer type);
}
